<?php
/**
 * Created by PhpStorm.
 * User: LAKECASEY
 * Date: 2018/12/7
 * Time: 10:29
 */
namespace App\Http\Controllers\Web;
use App\Http\Controllers\Controller;
use App\model\Adverts;
use App\model\Chain;
use App\model\China;
use App\model\Information;
use App\model\Message;
use App\model\Misspeople;
use App\model\Service;
use Illuminate\Http\Request;

class SiteController extends Controller
{
    /**
     * 网站首页
     */
    public function index()
    {
        //seo配置文件
        $SEO = config('seo.index');
        $title = $SEO['title'];
        $keywords = $SEO['keywords'];
        $description = $SEO['description'];
        //首页
        $active = 1;
        //查询所有地区
        $areaname = new China();
        $areaarray = $areaname->getAllarea();
        //获取友链
        $dv = new Chain();
        $friendurl = $dv->getAllurl();
        //获取最新发布寻人消息
        $m_db = new Misspeople();
        $new_msg = $m_db->getNewmsg();
        //首页默认展示家人寻亲人信息
        $default = $m_db->findtype_msg_all();
        //推荐综合资讯
        $news= new Information();
        $recommend_news = $news->getSuggest(1);
        $recommend_news_two = $news->getSuggest(2);
        $recommend_news_three = $news->getSuggest(3);
        $recommend_news_four = $news->getSuggest(4);
        //查询焦点
        $hotnews = $news->getAtten();
        //推荐的寻人
        $peo = new Misspeople();
        $getrecommend = $peo->getSuggest();
        //随机抽取寻人启事
        $randdatas = $peo->getRand();
        //获取终于等到你
        $isyou = $news->getRandNewsfour();
        //随机取出资讯
        $getrandnews = $news->getRand();

        //首页轮播图
        $advers = new Adverts();
        $loading_ad = $advers->getad(1);
        $isMobile = $this->isMobile();
        if ($isMobile)
        {
            return view('wap.site.index',compact('title','keywords','description','areaarray','active','friendurl','new_msg','default','recommend_news','recommend_news_two','recommend_news_three','hotnews','getrecommend','randdatas','gohome','isyou','getrandnews','loading_ad'));
        }
        else
        {
            return view('web.site.index',compact('title','keywords','description','areaarray','active','friendurl','new_msg','default','recommend_news','recommend_news_two','recommend_news_three','hotnews','getrecommend','randdatas','gohome','isyou','getrandnews','loading_ad','recommend_news_four'));
        }
    }

    /**
     * 留言服务
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|\think\response\View
     */
    public function message(Request $request)
    {
        //seo配置文件
        $SEO = config('seo.message');
        $title = $SEO['title'];
        $keywords = $SEO['keywords'];
        $description = $SEO['description'];
        //首页
        $active = 4;
        $db = new Message();
        $data = $db->getAllmessage();
        //判断是否是移动端
        $isMobile = $this->isMobile();
        if ($isMobile)
        {
            return view('wap.site.leavemessage',compact('title','keywords','description','active','data'));
        }
        else
        {
            return view('web.site.leavemessage',compact('title','keywords','description','active','data'));
        }

    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function addmesage(Request $request)
    {
            //入库留言
            $db = new Message();
            return $db->Addmessage($request);
    }
    /**
     * 增值服务
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|\think\response\View
     */
    public function addservice()
    {
        //seo配置文件
        $SEO = config('seo.addservice');
        $title = $SEO['title'];
        $keywords = $SEO['keywords'];
        $description = $SEO['description'];
        //首页
        $active = 5;
        //获取资讯
        $adb= new Information();
        $oters = $adb->getRand();
        //获取广告位
        $ad = new Adverts();
        $news_ad = $ad->getad(6);
        $isMobile = $this->isMobile();
        //首页轮播图
        $advers = new Adverts();
        $loading_ad = $advers->getad(1);
        //获取增值服务信息
        $addb= new Service();
        $addmsg = $addb->getMsg();
        if ($isMobile)
        {
            return view('wap.site.addservice',compact('title','keywords','description','loading_ad','addmsg'));
        }
        else
        {
            return view('web.site.addservice',compact('title','keywords','description','active','oters','news_ad','addmsg'));
        }

    }

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|\think\response\View
     */
    public function sendmsgform()
    {
        //seo配置文件
        $SEO = config('seo.message');
        $title = $SEO['title'];
        $keywords = $SEO['keywords'];
        $description = $SEO['description'];
        $active = '4-1';
        return view('wap.site.sendform',compact('title','description','keywords','active'));
    }

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|\think\response\View
     */
    public function aboutus()
    {
        //seo配置文件
        $SEO = config('seo.index');
        $title = $SEO['title'];
        $keywords = $SEO['keywords'];
        $description = $SEO['description'];
        return view('web.site.aboutus',compact('title','description','keywords'));
    }
}